﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.Slaughter;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Slaughter
{
    public class UpdataSlaughterCommandHand : IRequestHandler<UpdataSlaughterCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<SlaughterModel> _slaughter;
        private readonly IMapper _mapper;

        public UpdataSlaughterCommandHand(IBaseRepository<SlaughterModel> slaughter, IMapper mapper)
        {
            _slaughter = slaughter;
            _mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(UpdataSlaughterCommand request, CancellationToken cancellationToken)
        {
            var result=new ApiResult<int>();
            var slaugh = _mapper.Map<SlaughterModel>(request);
            _slaughter.UpdateList(slaugh);
            result.Message = "修改屠宰信息成功";
            return Task.FromResult(result);
        }
    }
}
